using System;
using System.Reflection;

namespace OpenSource.SpreadsheetFactory.Internal
{
    internal sealed class FieldColumn<T> : Column<T>
    {
        private FieldInfo Field { get; set; }

        internal FieldColumn(FieldInfo field) : base(field)
        {
            if (field == null)
            {
                throw new ArgumentNullException("field");
            }
            this.Field = field;
        }

        internal sealed override Type GetColumnType()
        {
            return this.Field.FieldType;
        }

        internal sealed override object GetColumnValue(T instance)
        {
            return this.Field.GetValue(instance);
        }

        protected sealed override MemberInfo Member
        {
            get
            {
                return this.Field;
            }
        }
    }
}

